package com.twu.book;

import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Iterator;

/**
 * Created with IntelliJ IDEA.
 * User: root
 * Date: 6/28/13
 * Time: 2:11 AM
 * To change this template use File | Settings | File Templates.
 */
public class BookList {

    protected BookList() {
    }

    private static ArrayList<Book> booklist = new ArrayList();

    public static void insertBook(Book book)
    {
        booklist.add(book);
    }

    public static void listall(PrintStream output)
    {
        Iterator<Book> book = booklist.iterator();
        while(book.hasNext())
        {
            Book it = book.next();
            output.print("["+it.getNumber()+"] "+it.getTitle()+" "+it.getAuthor()+"\n");
        }
    }

    public static Book findBookByNumber(String param) {
        Iterator<Book> book = booklist.iterator();
        while(book.hasNext())
        {
            Book it = book.next();
            if( it.getNumber().equals(param))
                return it;
        }
        return null;  //To change body of created methods use File | Settings | File Templates.
    }
}
